
//
//  WFInformationBaseTitleView.m
//  谷居
//
//  Created by dllo on 16/6/27.
//  Copyright © 2016年 刘万方. All rights reserved.
//

#import "WFInformationBaseTitleView.h"
#import "Masonry.h"
#import "WFLabel.h"
#import "UIImageView+AFNetworking.h"
#import "WFHandleURL.h"
#import "WFUserModel.h"
#import "WFUserimageModel.h"
@interface WFInformationBaseTitleView ()
@property (nonatomic, retain) WFImageView *photoImageView; /** 头像. */

@property (nonatomic, retain) WFUIView *houseInformationsView; /** 房子信息底层view*/

@property (nonatomic, retain) WFUIView *satuationBaseView;; /** 楼盘位置底层view. */

@property (nonatomic, retain) WFImageView *baseImageVeiw; /** titleView的底层图片. */

@property (nonatomic, retain) UILabel *nameLabel; /** 设计者姓名. */

@property (nonatomic, retain) WFImageView *nameImageView; /** 姓名旁边的图片. */

@property (nonatomic, retain) WFLabel *baseImageViewBottomLabel; /** 背景图片的下方label. */

@property (nonatomic, retain) WFUIView *midBaseView; /** 中间的底层view. */

@property (nonatomic, retain) WFUIView *bottomBaseView; /** 最下面的底层view. */

@property (nonatomic, retain) UILabel *styleLabel;

@property (nonatomic, retain) UILabel *areaLabel;

@property (nonatomic, retain) UILabel *typeLabel;

@property (nonatomic, retain) UILabel *costLabel;

@property (nonatomic, retain) WFLabel *styleLabelW;

@property (nonatomic, retain) WFLabel *areaLabelW;

@property (nonatomic, retain) WFLabel *typeLabelW;

@property (nonatomic, retain) WFLabel *costLabelW;

@property (nonatomic, retain) WFImageView *buildImageView; /** 楼盘图标. */

@property (nonatomic, retain) WFLabel *bottomLabel;
@end
@implementation WFInformationBaseTitleView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (void)createTitleViewWithModel:(WFInformationModel *)model {
    
    
    _baseImageVeiw = [[WFImageView alloc] init];
    [self addSubview:_baseImageVeiw];
    [_baseImageVeiw release];
    [_baseImageVeiw mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(SELF_HEIGHT / 3 * 2);
        make.width.and.top.equalTo(self);
        
    }];
    [_baseImageVeiw setImageWithURL:[NSURL URLWithString:[WFHandleURL getPicURL:model.coverPhoto]] placeholderImage:nil];
    
    
    
    _photoImageView = [[WFImageView alloc]init];
    [self addSubview:_photoImageView];
    [_photoImageView release];
    
    [_photoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(60, 60));
        make.center.equalTo(_baseImageVeiw);
    }];
    _photoImageView.layer.borderWidth = 1.5;
    _photoImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    _photoImageView.layer.cornerRadius = 30;
    _photoImageView.layer.masksToBounds = YES;
    WFUserModel *userModel = model.user;
    

    [_photoImageView setImageWithURL:[NSURL URLWithString:(NSString *)(((NSDictionary *)userModel)[@"userImage"][@"small"])]];
    _photoImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPhotoImage:)];
    [_photoImageView addGestureRecognizer:tap];
    [tap release];
    
    
    
    _nameLabel = [[UILabel alloc] init];
    [self addSubview:_nameLabel];
    [_nameLabel release];
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self);
        make.top.equalTo(_photoImageView.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(60, 20));
    }];
    _nameLabel.backgroundColor = [UIColor clearColor];
    _nameLabel.text = ((NSDictionary *)userModel)[@"userName"];
    _nameLabel.textColor = [UIColor whiteColor];
    
    
    
    _nameImageView = [[WFImageView alloc] init];

    [self addSubview:_nameImageView];
    [_nameImageView release];

    [_nameImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_nameLabel.mas_right).offset(10);
        make.centerY.equalTo(_nameLabel);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    _nameImageView.image = [UIImage imageNamed:@"金牌.png"];
    
    
    _baseImageViewBottomLabel = [[WFLabel alloc] init];
    [self addSubview:_baseImageViewBottomLabel];
    [_baseImageViewBottomLabel release];
    _baseImageViewBottomLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];

    [_baseImageViewBottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.bottom.equalTo(_baseImageVeiw);
        make.height.mas_equalTo(20);
    }];
    _baseImageViewBottomLabel.text = model.title;
    _baseImageViewBottomLabel.textAlignment = 1;
    _baseImageViewBottomLabel.textColor = DAY_COLOR;
    
    _midBaseView = [[WFUIView alloc] init];
    [self addSubview:_midBaseView];
    [_midBaseView release];
    
    [_midBaseView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_baseImageVeiw.mas_bottom);
        make.width.equalTo(self);
        make.height.mas_equalTo(SELF_HEIGHT / 3 / 2);
    }];
    
    
    _bottomBaseView = [[WFUIView alloc] init];
    [self addSubview:_bottomBaseView];
    [_bottomBaseView release];
    [_bottomBaseView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.equalTo(self);
        make.top.equalTo(_midBaseView.mas_bottom).offset(10);
        make.bottom.equalTo(self).offset( - 10);
    }];
    
    
    _styleLabelW = [[WFLabel alloc] init];
    [_midBaseView addSubview:_styleLabelW];
    [_styleLabelW release];
    
    
    _styleLabel = [[UILabel alloc] init];
    [_midBaseView addSubview:_styleLabel];
    [_styleLabel release];
    
    _areaLabel = [[UILabel alloc] init];
    [_midBaseView addSubview:_areaLabel];
    [_areaLabel release];
    
    _areaLabelW = [[WFLabel alloc] init];
    [_midBaseView addSubview:_areaLabelW];
    [_areaLabelW release];
    
    
    _typeLabel = [[UILabel alloc] init];
    [_midBaseView addSubview: _typeLabel];
    [_typeLabel release];
    
    _typeLabelW = [[WFLabel alloc] init];
    [_midBaseView addSubview:_typeLabelW];
    [_typeLabelW release];
    
    _costLabel = [[UILabel alloc] init];
    [_midBaseView addSubview:_costLabel];
    [_costLabel release];
    
    _costLabelW = [[WFLabel alloc] init];
    [_midBaseView addSubview:_costLabelW];
    [_costLabelW release];
    
    
    
    [_styleLabelW mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self).offset(20);
        make.top.equalTo(_midBaseView).offset(10);
        make.size.mas_equalTo(CGSizeMake(40, 18));
        
    }];
    _styleLabelW.text = @"风格:";
    
    [_styleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_styleLabelW.mas_right).offset(20);
        make.centerY.height.equalTo(_styleLabelW);
        make.width.mas_lessThanOrEqualTo(50);
        
    }];
    
    _styleLabel.text = model.styleShow;
    _styleLabel.textColor = [UIColor purpleColor];
    
    
    
    [_typeLabelW mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_styleLabelW);
        make.bottom.equalTo(_midBaseView.mas_bottom).offset(-10);
        make.size.equalTo(_styleLabelW);
    }];
    _typeLabelW.text = @"户型:";
    
    [_typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.equalTo(_typeLabelW);
        make.centerX.width.equalTo(_styleLabel);
    }];
    
    _typeLabel.text = model.typeShow;
    _typeLabel.textColor = [UIColor purpleColor];
    
    
    [_areaLabelW mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self).offset(SELF_WIDTH / 2 + 20);
        make.size.centerY.equalTo(_styleLabelW);
    }];
    _areaLabelW.text = @"面积:";

    [_areaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_areaLabelW.mas_right).offset(20);
        make.centerY.equalTo(_areaLabelW);
        make.width.equalTo(_styleLabel);
    }];
    
    _areaLabel.text = model.areaShow;
    _areaLabel.textColor = [UIColor purpleColor];
    
    
    [_costLabelW mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.centerX.equalTo(_areaLabelW);
        make.centerY.equalTo(_typeLabelW);
    }];
    _costLabelW.text = @"预算:";
    [_costLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.centerY.equalTo(_typeLabel);
        make.centerX.equalTo(_areaLabel);
    }];
    _costLabel.text = model.costShow;
    _costLabel.textColor = [UIColor purpleColor];

    _buildImageView = [[WFImageView alloc] init];
    [_bottomBaseView addSubview:_buildImageView];
    [_buildImageView release];
    
    [_buildImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.equalTo(_bottomBaseView).offset(10);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    
    _buildImageView.image = [UIImage imageNamed:@"buid.png"];
    
    _bottomLabel = [[WFLabel alloc] init];
    [_bottomBaseView addSubview:_bottomLabel];
    [_bottomLabel release];
    _bottomLabel.text = [NSString stringWithFormat:@"所在楼盘: %@", model.buildingName];
//    _bottomLabel.textColor = [UIColor lightTextColor];
    
    
    [_bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_buildImageView.mas_right).offset(20);
        make.right.equalTo(_bottomBaseView).offset(-20);
        make.top.equalTo(_bottomBaseView).offset(10);
        make.bottom.equalTo(_bottomBaseView).offset(-10);
    }];
    
}

- (void)clickPhotoImage:(UITapGestureRecognizer *)tap {
    [self.delegate makePush];
}

- (void)dealloc {
    [super dealloc];
}
@end
